@extends('admin.base')

@section('content')
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="name" id="name" placeholder="请输入姓名" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="phone" id="phone" placeholder="请输入手机号" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="card_no" id="card_no" placeholder="请输入身份证号" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <select name="verify_status" id="verify_status">
                            <option value="">请选择认证状态</option>
                            <option value="0">待提交</option>
                            <option value="1">已全部提交</option>
                            <option value="10">已提交身份信息</option>
                            <option value="20">已提交车辆信息</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <select name="audit_status" id="audit_status">
                            <option value="">请选择审核状态</option>
                            <option value="10">待审核</option>
                            <option value="20">审核通过</option>
                            <option value="30">审核不通过</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" lay-submit lay-filter="search-form">搜 索</button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>

            {{--<script type="text/html" id="options">--}}
            {{--<div class="layui-btn-group">--}}
            {{--@can('member.member.create')--}}
            {{--<a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>--}}
            {{--@endcan--}}
            {{--@can('member.member.destroy')--}}
            {{--<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">禁用</a>--}}
            {{--@endcan--}}
            {{--</div>--}}
            {{--</script>--}}
            <script type="text/html" id="status">
                <input disabled type="checkbox" lay-skin="switch" lay-text="启用|禁用" @{{ d.status==1?'checked':'' }}>
            </script>
        </div>
    </div>
@endsection

@section('script')
    @can('member.driver')
        <script>
            layui.use(['layer', 'table', 'form'], function () {
                var layer = layui.layer;
                var form = layui.form;
                var table = layui.table;
                //用户表格初始化
                var dataTable = table.render({
                    elem: '#dataTable'
                    , height: 500
                    , url: "{{ route('admin.driver.data') }}" //数据接口
                    , page: true //开启分页
                    , cols: [[ //表头
                        {field: 'id', width: 60, title: 'ID', sort: true}
                        , {field: 'name', title: '姓名', width: 100}
                        , {field: 'phone', width: 120, title: '手机'}
                        , {field: 'uuid', width: 300, title: '用户UUID'}
                        , {field: 'card_no', title: '身份证号', width: 100}
                        , {field: 'status', title: '司机状态', width: 100, toolbar: "#status"}
                        , {
                            field: 'verify_status', title: '认证状态', width: 130, templet: function (d) {
                                if (d.verify_status == 0) {
                                    return '待提交';
                                } else if (d.verify_status == 1) {
                                    return '已全部提交';
                                } else if (d.verify_status == 10) {
                                    return '已提交身份信息';
                                } else if (d.verify_status == 20) {
                                    return '已提交车辆信息';
                                }
                            }
                        }
                        , {
                            field: 'audit_status', title: '审核状态', width: 100, templet: function (d) {
                                if (d.audit_status == undefined) {
                                    return '--';
                                } else if (d.audit_status == 10) {
                                    return '待审核';
                                } else if (d.audit_status == 20) {
                                    return '审核通过';
                                } else if (d.audit_status == 30) {
                                    return '审核不通过';
                                }
                            }
                        }
                        , {field: 'created_at', title: '注册时间', width: 180}
                        , {field: 'driver_uptime', title: '最新认证时间', width: 180}
                        , {
                            fixed: 'right', width: 150, align: 'center', title: '操作', templet: function (d) {
                                right = '';
                                if (d.audit_status >= 10) {
                                    right += '<a class="layui-btn layui-btn-sm" lay-event="show">详情</a>';
                                }
                                @can('member.driver')
                                if (d.audit_status == 10) {
                                    right += '<a class="layui-btn layui-btn-info layui-btn-sm" lay-event="verify">审核</a>';
                                }
                                @endcan
                                return right;
                            }
                        }
                    ]]
                });

                //监听工具条
                table.on('tool(dataTable)', function (obj) { //注：tool是工具条事件名，dataTable是table原始容器的属性 lay-filter="对应的值"
                    var data = obj.data //获得当前行数据
                        , layEvent = obj.event; //获得 lay-event 对应的值
                    if (layEvent === 'show') {
                        location.href = '/admin/driver/' + data.id + '/show';
                    } else if (layEvent === 'verify') {
                        location.href = '/admin/driver/' + data.id + '/verify';
                    }
                });

                //搜索
                form.on('submit(search-form)', function (data) {
                    var fields = data.field;
                    dataTable.reload({
                        page: {
                            curr: 1 //重新从第 1 页开始
                        },
                        where: fields // 搜索字段
                    });
                    return false;
                });
            })
        </script>
    @endcan
@endsection



